package com.cloud.nacosConfigLoad;

import com.cloud.nacosConfigLoad.test.TestLoad;
import com.cloud.utils.ApplicationContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * 启动回调
 */

@Component
public class NacosRunner implements ApplicationRunner {
    @Autowired
    private TestLoad testLoad;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        // 获取 HotDeploymentManager 实例并开始监控
        HotDeploymentManager manager = ApplicationContextHolder.getBean(HotDeploymentManager.class);
        // 项目的相对路径
        String relativePath = "target/classes/com/cloud/nacosConfigLoad/test";
        // 监控目录下的 .class 文件变化
        manager.monitorAndReloadBeans(relativePath);
        System.out.println(testLoad.getName());
        int i = 0;
//        while (true) {
//            Thread.sleep(1000);
//            System.out.println(testLoad.getName());
//            i++;
//            if (i == 10) {
//
//            }
//
//        }

    }
}
